home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_12_04
/
suereth
/
timeexp.c
< prev
Wrap
C/C++ Source or Header
|
1994-02-13
|
34KB
|
931 lines
Listing 1 The expansion code for time
/* Copyright (c) 1993 Russell Suereth */
#include "natural.h"
#define PROBABILITY 220
#define CHARACTERISTIC 221
#define LOGICAL_NECESSITY 222
#define TENSES_ERROR 210
#define TIME_MEANING_ERROR 211
#define NUMBER_ERROR 212
#define POINT_OF_TIME 100
#define DAY 101
#define PERIOD_OF_TIME 102
#define DURATION 103
#define BEFORE 104
#define AFTER 105
#define SINCE 106
#define BETWEEN 107
#define UNTIL 108
#define LAST 111
#define NEXT 112
#define EACH 113
#define EVERY 114
#define ALL 115
int ask_meaning(void);
void check_time(void);
void derive_aux_meaning(void);
void derive_time_meaning(void);
int check_agreement(void);
void check_time(void);
void agreement_error(int);
void aux_meaning_response(void);
int check_underlying3(void);
char times[20][31];
unsigned char time_meaning[20];
/*****************************************************/
/* Determine if the input sentence contains a known, */
/* underlying structure. If it does, then assign the */
/* correct types and phrases for the words. */
/*****************************************************/
int check_underlying()
{
int i = 0;
/* Structure PRON-AUX-VERB-PREP-DET-NOUN */
if ( (check_type("PRON", i) == 0) &&
(check_type("AUX", i+1) == 0) &&
(check_type("VERB", i+2) == 0) &&
(check_type("PREP", i+3) == 0) &&
(check_type("DET", i+4) == 0) &&
(check_type("NOUN", i+5) == 0) ) {
strcpy(prime_types[i], "PRON");
strcpy(prime_types[i+1], "AUX");
strcpy(prime_types[i+2], "VERB");
strcpy(prime_types[i+3], "PREP");
strcpy(prime_types[i+4], "DET");
strcpy(prime_types[i+5], "NOUN");
strcpy(phrases[i], "NOUNPHRASE");
strcpy(phrases[i+1], "VERBPHRASE");
strcpy(phrases[i+2], "VERBPHRASE");
strcpy(phrases[i+3], "PREPPHRASE");
strcpy(phrases[i+4], "PREPPHRASE");
strcpy(phrases[i+5], "PREPPHRASE");
strcpy(auxiliaries[sentence], word_array[i+1]);
get_aux();
return(0);
}
/* Structure NAME-AUX-VERB-PREP-DET-NOUN */
if ( (check_type("NAME", i) == 0) &&
(check_type("AUX", i+1) == 0) &&
(check_type("VERB", i+2) == 0) &&
(check_type("PREP", i+3) == 0) &&
(check_type("DET", i+4) == 0) &&
(check_type("NOUN", i+5) == 0) ) {
strcpy(prime_types[i], "NAME");
strcpy(prime_types[i+1], "AUX");
strcpy(prime_types[i+2], "VERB");
strcpy(prime_types[i+3], "PREP");
strcpy(prime_types[i+4], "DET");
strcpy(prime_types[i+5], "NOUN");
strcpy(phrases[i], "NOUNPHRASE");
strcpy(phrases[i+1], "VERBPHRASE");
strcpy(phrases[i+2], "VERBPHRASE");
strcpy(phrases[i+3], "PREPPHRASE");
strcpy(phrases[i+4], "PREPPHRASE");
strcpy(phrases[i+5], "PREPPHRASE");
strcpy(auxiliaries[sentence], word_array[i+1]);
get_aux();
return(0);
}
/* Structure NAME-AUX-AUX-AUX-VERB-PREP-TIME-TIME*/
if ( (check_type("NAME", i) == 0) &&
(check_type("AUX", i+1) == 0) &&
(check_type("AUX", i+2) == 0) &&
(check_type("AUX", i+3) == 0) &&
(check_type("VERB", i+4) == 0) &&
(check_type("PREP", i+5) == 0) &&
(check_type("TIME", i+6) == 0) &&
(check_type("TIME", i+7) == 0) ) {
strcpy(prime_types[i], "NAME");
strcpy(prime_types[i+1], "AUX");
strcpy(prime_types[i+2], "AUX");
strcpy(prime_types[i+3], "AUX");
strcpy(prime_types[i+4], "VERB");
strcpy(prime_types[i+5], "TIME");
strcpy(prime_types[i+6], "TIME");
strcpy(prime_types[i+7], "TIME");
strcpy(phrases[i], "NOUNPHRASE");
strcpy(phrases[i+1], "VERBPHRASE");
strcpy(phrases[i+2], "VERBPHRASE");
strcpy(phrases[i+3], "VERBPHRASE");
strcpy(phrases[i+4], "VERBPHRASE");
strcpy(phrases[i+5], "TIMEPHRASE");
strcpy(phrases[i+6], "TIMEPHRASE");
strcpy(phrases[i+7], "TIMEPHRASE");
strcpy(auxiliaries[sentence], word_array[i+1]);
strcat(auxiliaries[sentence], " ");
strcat(auxiliaries[sentence], word_array[i+2]);
strcat(auxiliaries[sentence], " ");
strcat(auxiliaries[sentence], word_array[i+3]);
get_aux();
return(0);
}
/* Structure NAME-AUX-AUX-AUX-VERB-PREP-TIME */
if ( (check_type("NAME", i) == 0) &&
(check_type("AUX", i+1) == 0) &&
(check_type("AUX", i+2) == 0) &&
(check_type("AUX", i+3) == 0) &&
(check_type("VERB", i+4) == 0) &&
(check_type("PREP", i+5) == 0) &&
(check_type("TIME", i+6) == 0) ) {
strcpy(prime_types[i], "NAME");
strcpy(prime_types[i+1], "AUX");
strcpy(prime_types[i+2], "AUX");
strcpy(prime_types[i+3], "AUX");
strcpy(prime_types[i+4], "VERB");
strcpy(prime_types[i+5], "TIME");
strcpy(prime_types[i+6], "TIME");
strcpy(phrases[i], "NOUNPHRASE");
strcpy(phrases[i+1], "VERBPHRASE");
strcpy(phrases[i+2], "VERBPHRASE");
strcpy(phrases[i+3], "VERBPHRASE");
strcpy(phrases[i+4], "VERBPHRASE");
strcpy(phrases[i+5], "TIMEPHRASE");
strcpy(phrases[i+6], "TIMEPHRASE");
strcpy(auxiliaries[sentence], word_array[i+1]);
strcat(auxiliaries[sentence], " ");
strcat(auxiliaries[sentence], word_array[i+2]);
strcat(auxiliaries[sentence], " ");
strcat(auxiliaries[sentence], word_array[i+3]);
get_aux();
return(0);
}
/* Structure NAME-AUX-AUX-AUX-VERB-TIME-TIME */
if ( (check_type("NAME", i) == 0) &&
(check_type("AUX", i+1) == 0) &&
(check_type("AUX", i+2) == 0) &&
(check_type("AUX", i+3) == 0) &&
(check_type("VERB", i+4) == 0) &&
(check_type("TIME", i+5) == 0) &&
(check_type("TIME", i+6) == 0) ) {
strcpy(prime_types[i], "NAME");
strcpy(prime_types[i+1], "AUX");
strcpy(prime_types[i+2], "AUX");
strcpy(prime_types[i+3], "AUX");
strcpy(prime_types[i+4], "VERB");
strcpy(prime_types[i+5], "TIME");
strcpy(prime_types[i+6], "TIME");
strcpy(phrases[i], "NOUNPHRASE");
strcpy(phrases[i+1], "VERBPHRASE");
strcpy(phrases[i+2], "VERBPHRASE");
strcpy(phrases[i+3], "VERBPHRASE");
strcpy(phrases[i+4], "VERBPHRASE");
strcpy(phrases[i+5], "TIMEPHRASE");
strcpy(phrases[i+6], "TIMEPHRASE");
strcpy(auxiliaries[sentence], word_array[i+1]);
strcat(auxiliaries[sentence], " ");
strcat(auxiliaries[sentence], word_array[i+2]);
strcat(auxiliaries[sentence], " ");
strcat(auxiliaries[sentence], word_array[i+3]);
get_aux();
return(0);
}
/* Structure NAME-AUX-AUX-VERB-PREP-TIME-TIME */
if ( (check_type("NAME", i) == 0) &&
(check_type("AUX", i+1) == 0) &&
(check_type("AUX", i+2) == 0) &&
(check_type("VERB", i+3) == 0) &&
(check_type("PREP", i+4) == 0) &&
(check_type("TIME", i+5) == 0) &&
(check_type("TIME", i+6) == 0) ) {
strcpy(prime_types[i], "NAME");
strcpy(prime_types[i+1], "AUX");
strcpy(prime_types[i+2], "AUX");
strcpy(prime_types[i+3], "VERB");
strcpy(prime_types[i+4], "TIME");
strcpy(prime_types[i+5], "TIME");
strcpy(prim